import { InfraFileModel } from '@/models/infraFile'
import { useModel, useSnapshot } from '@@/exports'
import { ModalForm, ProFormText } from '@ant-design/pro-components'
import { ProFormInstance } from '@ant-design/pro-form/lib'
import { useRef } from 'react'

export interface InfraFileUpdateModalProps {
  onFinish: (formData: any) => Promise<boolean | void>
}

const InfraFileUpdateModal = (props: InfraFileUpdateModalProps) => {
  let { getDictList } = useModel('dict')
  let infraFileState = useSnapshot(InfraFileModel.state)
  let { actions: infraFileActions } = InfraFileModel
  const formRef = useRef<ProFormInstance>()
  return (
    <>
      <ModalForm
        key={infraFileState.infraFile?.id || -1}
        formRef={formRef}
        title={infraFileState.infraFile ? '修改文件' : '添加文件'}
        open={infraFileState.updateModalState}
        initialValues={infraFileState.infraFile}
        onFinish={props.onFinish}
        onOpenChange={infraFileActions.setUpdateModalState}
      >
        <ProFormText label="文件编号" hidden name="id" rules={[{ required: true, message: '请填写文件编号' }]} />

        <ProFormText label="配置编号" name="configId" />

        <ProFormText label="文件名" name="name" />

        <ProFormText label="文件路径" name="path" rules={[{ required: true, message: '请填写文件路径' }]} />

        <ProFormText label="文件 URL" name="url" rules={[{ required: true, message: '请填写文件 URL' }]} />

        <ProFormText label="文件类型" name="type" />

        <ProFormText label="文件大小" name="size" rules={[{ required: true, message: '请填写文件大小' }]} />

        <ProFormText label="创建者" name="creator" />

        <ProFormText label="创建时间" name="createTime" rules={[{ required: true, message: '请填写创建时间' }]} />

        <ProFormText label="更新者" name="updater" />

        <ProFormText label="更新时间" name="updateTime" rules={[{ required: true, message: '请填写更新时间' }]} />

        <ProFormText label="是否删除" name="isDeleted" rules={[{ required: true, message: '请填写是否删除' }]} />
      </ModalForm>
    </>
  )
}

export default InfraFileUpdateModal
